home *** CD-ROM | disk | FTP | other *** search
/ AM/FM: Amiga Musicians' Freeware Magazine 1 / AM-FM 1.adf / TechCorner / transposedemo.a < prev    next >
Text File  |  1991-10-03  |  3KB  |  118 lines

  1. ;    transposedemo.a -- by Teijo Kinnunen
  2.  
  3. ; This program demonstrates the usage of both the input and output
  4. ; routines of midiroutines.a.
  5. ; It reads in notes from the MIDI-interface, prints the name of a
  6. ; note on the screen, and sends the note out after transposing it
  7. ; one octave up.
  8. ; (the code could be better optimized, but I think it's not vital)
  9.  
  10. ; Press CTRL-C to exit!!
  11.  
  12.     XREF    _GetSerial
  13.     XREF    _FreeSerial
  14.     XREF    _AddMIDIData
  15.  
  16.     XDEF    _sigmask
  17.     XDEF    _maintsk
  18.     XDEF    _inputbuff
  19.  
  20.     CODE
  21.         movem.l    d1-d7/a0-a6,-(sp)
  22. ; ------ Open the dos.library --------------------------------------------
  23.         movea.l    4,a6
  24.         lea    dosname(pc),a1
  25.         moveq    #0,d0
  26.         jsr    -$228(a6)    ;OpenLibrary()
  27.         tst.l    d0
  28.         beq.w    exit0
  29.         move.l    d0,dosbase
  30. ; ------ Get a signal bit for MIDI input notification --------------------
  31.         moveq    #-1,d0
  32.         jsr    -$14a(a6)    ;AllocSignal()
  33.         tst.l    d0
  34.         bmi.w    exit1
  35.         move.l    d0,sigbit
  36.         moveq    #1,d5
  37.         lsl.l    d0,d5
  38.         move.l    d5,_sigmask
  39.         or.l    #1<<12,d5    ;add SIGBREAKF_CTRL_C
  40. ; ------ Find the address of this task -----------------------------------
  41.         suba.l    a1,a1
  42.         jsr    -$126(a6)    ;FindTask()
  43.         move.l    d0,_maintsk
  44. ; ------ Get the serial port ---------------------------------------------
  45.         jsr    _GetSerial(pc)
  46.         tst.l    d0
  47.         bne.w    exit2
  48. ; ====== MAIN LOOP =======================================================
  49. mainloop    move.l    d5,d0
  50.         jsr    -$13e(a6)    ;Wait()
  51.         btst    #12,d0        ;SIGBREAK_CTRL_C?
  52.         bne.w    exit3
  53. ; make sure that the RBF doesn't disturb us by sending a new note before
  54. ; we've finished
  55.         move.l    _inputbuff,_inputbuff2
  56.         move.b    _inputbuff2(pc),d7
  57.         and.b    #$f0,d7
  58.         cmp.b    #$90,d7
  59.         bne.s    nowrite    ;if it's Note Off, we don't display its name
  60.         tst.b    _inputbuff2+2 ;if volume == 0, it's Note Off
  61.         beq.s    nowrite
  62.         moveq    #0,d7
  63.         move.b    _inputbuff2+1(pc),d7    ;get note number
  64.         divu    #12,d7
  65.         move.w    d7,d6        ;d6 = octave number
  66.         swap    d7        ;d7.w = note (0 - 11)
  67.         add.w    d6,d6        ;* 2
  68.         add.w    d7,d7
  69.         lea    notenames(pc),a0
  70.         lea    printbuff(pc),a1
  71.         move.w    0(a0,d7.w),(a1)+    ;note name
  72.         lea    octaves(pc),a0
  73.         move.w    0(a0,d6.w),(a1)+    ;octave
  74. ; ------ Write the note name ---------------------------------------------
  75.         move.l    a6,-(sp)
  76.         move.l    dosbase(pc),a6
  77.         jsr    -$3c(a6)    ;Output()
  78.         move.l    d0,d1
  79.         move.l    #printbuff,d2
  80.         moveq    #5,d3
  81.         jsr    -$30(a6)    ;Write()
  82.         move.l    (sp)+,a6
  83. ; ------ Transpose and send out the note ---------------------------------
  84. nowrite        add.b    #12,_inputbuff2+1    ;transpose octave up
  85.         bmi.s    nosendout        ;> 127 => not possible
  86.         lea    _inputbuff2(pc),a0
  87.         moveq    #3,d0
  88.         jsr    _AddMIDIData(pc)
  89. nosendout    bra.w    mainloop
  90. ; ========================================================================
  91. ; ------ Free the serial port --------------------------------------------
  92. exit3        jsr    _FreeSerial(pc)
  93. ; ------ Free the signal bit ---------------------------------------------
  94. exit2        move.l    sigbit(pc),d0
  95.         jsr    -$150(a6)    ;FreeSignal()
  96. ; ------ Close dos.library -----------------------------------------------
  97. exit1        move.l    dosbase(pc),a1
  98.         movea.l    4,a6
  99.         jsr    -$19e(a6)    ;CloseLibrary()
  100. ; ------ Exit ------------------------------------------------------------
  101. exit0        movem.l    (sp)+,d1-d7/a0-a6
  102.         moveq    #0,d0
  103.         rts
  104. ; ------ Variables -------------------------------------------------------
  105.  
  106. dosbase        dc.l    0
  107. sigbit        dc.l    0
  108. _maintsk    dc.l    0
  109. _sigmask    dc.l    0
  110. _inputbuff    dc.l    0
  111. _inputbuff2    dc.l    0
  112. notenames    dc.b    'C-C#D-D#E-F-F#G-G#A-A#B-'
  113. octaves        dc.b    '-10 1 2 3 4 5 6 7 8 9 '
  114. printbuff    dc.w    0,0
  115.         dc.b    13
  116. dosname        dc.b    'dos.library',0
  117.     END
  118.